package service;

import dao.UserDao;
import model.User;

/**
 * 用户服务类
 */
public class UserService {
    private UserDao userDao = new UserDao();

    // 用户登录
    public User login(String account, String password) {
        return userDao.findByAccountAndPassword(account, password);
    }

    // 用户注册
    public boolean register(User user) {
        // 检查用户名是否已存在
        if (userDao.findByAccount(user.getAccount()) != null) {
            return false;
        }
        return userDao.addUser(user);
    }

    public User getUserById(int userId) {
        return UserDao.getById(userId);
    }
}